package com.sos.core.game
{
	import com.sos.utils.ClassUtils;
	
	public class GameModType
	{
			
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------              
		
		public static const GENERAL:GameModType				= new GameModType(1, 	"General");
		public static const BUFF:GameModType                = new GameModType(2, 	"Debuff");
		public static const DEBUFF:GameModType              = new GameModType(3, 	"Buff");
		public static const GEAR:GameModType                = new GameModType(4, 	"Gear");
		public static const FREEKICK:GameModType            = new GameModType(5, 	"Freekick");
		public static const SWAP:GameModType            	= new GameModType(6, 	"Swap");
		public static const CHILD_EFFECT:GameModType        = new GameModType(7, 	"Child Effect");
		public static const FOUL:GameModType        		= new GameModType(8, 	"Foul");
		public static const YELLOW_CARD:GameModType        	= new GameModType(9, 	"Yellow Card");
		public static const RED_CARD:GameModType        	= new GameModType(10, 	"Red Card");
		public static const SCHOOL_BONUS:GameModType        = new GameModType(11,	"School Bonus");
		public static const STAMINA_REGEN:GameModType       = new GameModType(12,	"Stamina Regen"); 		// Half Time Stamina Regen
		public static const CARD_COST:GameModType       	= new GameModType(13,	"Card Cost");
		public static const CHILD_DEBUFF:GameModType       	= new GameModType(14,	"Child Debuff");
		public static const CHILD_BUFF:GameModType       	= new GameModType(15,	"Child Buff");
		public static const ANALISYS_MARKER:GameModType     = new GameModType(16,	"Analisys Marker");		// Defence School analisys marker
		public static const INVISIBLE_MARKER:GameModType    = new GameModType(17,	"Invisible Marker"); 	// Used to avoid double procs
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<GameModType>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<GameModType>();
			_list.push(GENERAL);
			_list.push(BUFF);
			_list.push(DEBUFF);
			_list.push(GEAR);
			_list.push(FREEKICK);
			_list.push(SWAP);
			_list.push(CHILD_EFFECT);
			_list.push(FOUL);
			_list.push(YELLOW_CARD);
			_list.push(RED_CARD);
			_list.push(SCHOOL_BONUS);
			_list.push(STAMINA_REGEN);
			_list.push(CARD_COST);
			_list.push(CHILD_DEBUFF);
			_list.push(CHILD_BUFF);
			_list.push(ANALISYS_MARKER);
			_list.push(INVISIBLE_MARKER);
			// Init!
			_initialized = true;
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function GameModType(id:uint, name:String)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("GameModType enum already created!");
			// Init
			_id    = id;
			_name  = name;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------              
		
		public function get id():uint
		{
			return _id;
		}
		
		
		public function get name():String
		{
			return _name;
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public function toString():String
		{
			return ClassUtils.getName(this) + "." + _name;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names of the game sides
		 * @return List of the names of the game sides
		 */
		public static function names():Array
		{
			var list:Array  = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * 
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		/**
		 * Search a GameModType by given id 
		 * @param id Id of the log target to find
		 * @return GameModType constant for the given id, null if no GameModType
		 * for the given id has been found
		 */             
		public static function getById(id:uint):GameModType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].id == id) return _list[i];
			}
			throw new Error("GameModType for id '" + id + "' unknown!");
		}
		
		/**
		 * Search a GameModType by given name 
		 * @param name Name of the log target to find
		 * @return GameModType constant for the given id, null if no GameModType
		 * for the given name has been found
		 */             
		public static function getByName(name:String):GameModType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			throw new Error("GameModType for name '" + name + "' unknown!");
		}
			
	}

}